<?php

class Cities extends Controller {

	function __construct() {
		parent::Controller();	
	}
	
	function index() {
		//Use this for your home page
		$data['title'] = "imerchant : City's Home";
		$data['main'] = 'cities/home';
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function add_cities() {
		//Add cities
		$data['title'] = "imerchant: Add cities";
		$data['main'] = 'cities/add_cities';
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function send() {
		if($this->input->post('cityname')) {
			$this->MCities->addCity();
			$data['title'] = "imerchant";
			$data['main'] = 'cities/sent';
			$this->load->vars($data);
			$this->load->view('template');
		} else {
		 show_error("This is not working");
		} 
	}
	
	function view_cities() {
		//View cities
		$data['title'] = "imerchant";
		$data['main'] = 'cities/view_cities';
		$data['result'] = $this->MCities->getAllCities();
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function delete() {
		//Delete cities
		$del_rows=0;
		if($this->input->post('delete')) {
			@$item=$_POST['item'];
			while (list ($key, $sel_id) = @each ($item)) { 
				$this->MCities->deleteCities($sel_id);
				$del_rows++; 
			} 
			
			$data['main'] = 'cities/delete';
			$data['del_rows'] = $del_rows;
			$this->load->vars($data);
			$this->load->view('template');
			
		} else {
		 show_error("This is not working");
		} 
	}
	
	function edit($id) {
		//Edit cities
		$data['result'] = $this->MCities->getCity($id);
		$data['main'] = 'cities/edit';
		$this->load->vars($data);
		$this->load->view('template');	
	}
	
	function update() {
		//update cities
		$id = $_POST['id'];
		if($this->input->post('update')) {
			$this->MCities->updateCity($id);
			$data['title'] = "imerchant";
			$data['main'] = 'cities/update';
			$this->load->vars($data);
			$this->load->view('template');
		} else {
		 show_error("This is not working");
		} 
	}
}

/* End of file cities.php */